// 通用键名
const INFO_KEY = 'GUYUENA_shopping_info'

const HISTORY_KEY = 'GUYUENA_history_list'

const CATEGORYID = 'GUYUENA_categoryId'

// 获取个人信息
export const getInfo = () => {
  const defaultObj = { token: '', phone: '' }
  const result = localStorage.getItem(INFO_KEY)
  return result ? JSON.parse(result) : defaultObj
}

// 设置个人信息
export const setInfo = (obj) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(obj))
}

// 移除个人信息
export const removeInfo = () => {
  localStorage.removeItem(INFO_KEY)
}

// 获取搜索记录
export const getHistoryList = () => {
  const result = localStorage.getItem(HISTORY_KEY)
  return result ? JSON.parse(result) : []
}

// 设置搜索记录
export const setHistoryList = (arr) => {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(arr))
}

// 获取分类id
export const getCategoryId = () => {
  const result = localStorage.getItem(CATEGORYID)
  return result ? JSON.parse(result) : null
}

// 设置搜索记录
export const setCategoryId = (arr) => {
  localStorage.setItem(CATEGORYID, JSON.stringify(arr))
}
